import {delay} from 'redux-saga'
import {take, put, call, all} from 'redux-saga/effects'

function* asyncPlus(action){
  yield delay(1000)
  const {payload} = action
  yield put({ type: 'plus', payload })
}

function* asyncMinus(action){
  yield delay(1000)
  const {payload} = action
  yield put({ type: 'minus', payload })
}

function* watchAsyncPlus(){
  while(true){
    const action = yield take("asyncPlus")
    yield call(asyncPlus, action)
  }
}
function* watchAsyncMinus(){
  while(true){
    const action = yield take("asyncMinus")
    yield call(asyncMinus, action)
  }
}

export default function* () {
  yield all([
    watchAsyncPlus(),
    watchAsyncMinus()
  ])
}